﻿using Microsoft.EntityFrameworkCore.Query;
using System.Linq.Expressions;


namespace SBlogCore.Common.DatabaseAccessor.Repositorys.EFCore
{
    public partial interface IRepository<TEntity> where TEntity : class, IBaseEntity
    {
        #region 修改
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        void Update(TEntity entity);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="entityParams"></param>
        void UpdateRange(params TEntity[] entityParams);
        /// <summary>
        /// 异步修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task UpdateAsync(TEntity entity);
        /// <summary>
        /// 异步批量修改
        /// </summary>
        /// <param name="entityParams"></param>
        /// <returns></returns>
        Task UpdateRangeAsync(params TEntity[] entityParams);
        /// <summary>
        /// 修改立即保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int UpdateNow(TEntity entity);
        /// <summary>
        /// 批量修改立即保存
        /// </summary>
        /// <param name="entityParams"></param>
        /// <returns></returns>
        int UpdateRangeNow(params TEntity[] entityParams);
        /// <summary>
        /// 异步修改立即保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> UpdateNowAsync(TEntity entity);
        /// <summary>
        /// 异步批量修改立即保存
        /// </summary>
        /// <param name="entityParams"></param>
        /// <returns></returns>
        Task<int> UpdateRangeNowAsync(params TEntity[] entityParams);

        /// <summary>
        /// 更新一条记录指定字段的值
        /// </summary>
        /// <param name="model">数据实体</param>
        /// <param name="updateColumns">指定字段</param>
        /// <returns></returns>
        void Update(TEntity model, params string[]? updateColumns);
        /// <summary>
        /// 更新一条记录指定字段的值
        /// </summary>
        /// <param name="model"></param>
        /// <param name="names"></param>
        void Update(TEntity model, IEnumerable<string> names);
        /// <summary>
        /// 按条件批量修改
        /// </summary>
        /// <param name="setPropertyCalls"></param>
        /// <returns></returns>
        int ExecuteUpdate(Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls);
        /// <summary>
        /// 按条件批量异步修改
        /// </summary>
        /// <param name="setPropertyCalls"></param>
        /// <returns></returns>
        Task<int> ExecuteUpdateAsync(
            Expression<Func<SetPropertyCalls<TEntity>, SetPropertyCalls<TEntity>>> setPropertyCalls);
        #endregion
    }
}